<template>
  <div class="hunk">
      <div class="search">
        <img v-if="baseUrl" :src="baseUrl+'search.png'" >
        <input type="text" placeholder="请输入地址、门牌号" @input="searchInput">
      </div>
      <div class="type-list">
        <div class="type-item">
          <div class="item-lable">房屋状态</div>
          <div class="item">
            <span v-for="(item,index) in housetypeList" :key="index" :class="item.color" @click="clickBtn(item,1)">
              {{item.text}}
              <img v-if="item.ischeck" :src="baseUrl+'check.png'" >
            </span>
          </div>
        </div>
        <div class="newItem">
          <div class="type-item">
            <div class="item-lable">整租/合租</div>
            <div class="item">
              <span v-for="(item,index) in outtypeList" :key="index" :class="item.color" @click="clickBtn(item,2)">
                {{item.text}}
                <img v-if="item.ischeck" :src="baseUrl+'check.png'" >
              </span>
            </div>
          </div>
          <div class="type-item">
            <div class="item-lable">房屋属性</div>
            <div class="item">
              <span v-for="(item,index) in houseattributeList" :key="index" :class="item.color" @click="clickBtn(item,3)">
                {{item.text}}
                <img v-if="item.ischeck" :src="baseUrl+'check.png'" >
              </span>
            </div>
          </div>
        </div>
        
      </div>
      <slot />
      <scroll-view
        class="home-list"
        scroll-y="true"
        :refresher-enabled="refresherEnabled"
        @refresherpulling="_onPulling"
        :refresher-triggered="triggered"
        @refresherrefresh="onRefresh"
        @refresherrestore="triggered = false"
        @refresherabort="triggered = false"
        @scrolltolower="_onLoadmore"
      >
      <!-- <div class="home-list"> -->
        <div class="home-item" v-for="(item1, idx) in list" :key="idx">
          <div class="home-name">{{item1.address}}</div>
          <div class="item-list">
            <div v-for="(item, index) in item1.houseLists" :key="index" :class="['one', check(item) ? (item.tag == 0 ? typeList[0].bgcolor : typeList[1].bgcolor) : typeList[2].bgcolor]" @click="clickitem(item)">
              <div class="top" style="width:60px">
                <img v-if="isImge(item)" :src="isImge(item) == 1 ? typeList[1].img : typeList[0].img " />
              </div>
              <div class="miaoshu">{{outtypeList[item.outtype].text}}-{{item.roomno}}</div>
              <div class="yuezu">
                <span>{{item.showlowrent}}</span>
                /月
              </div>
              <div class="enddays" v-if="item.enddays">
                授权剩余：<span :class="{'active':item.enddays<15}">{{item.enddays}}</span>
              </div>
              <div :class="['type', check(item) == 1 ? (item.hostingflag ? 'type2' : 'type1') : 'type3']">
                <img :src="check(item) == 1 ? (item.hostingflag ? typeList[1].type : typeList[0].type) : typeList[2].type" alt="" srcset="">
              </div>
            </div>
          </div>
        </div>
      <!-- </div> -->
      <div v-if="isnone<1" class="none">
        <img v-if="baseUrl" :src="baseUrl+'imgs/imgs/none.png'" alt="">
      </div>
      </scroll-view>
  </div>
</template>

<script>
const imgUrl = `${process.env.VUE_APP_BASE_IMG_URL}`

export default {
  data() {
    return {
      refresherEnabled: true,
      triggered:false,
      typeList: [
        { type: imgUrl+'house/zichi.png', img: imgUrl+'house/jjjz.png', bgcolor: 'zc'},
        { type: imgUrl+'house/tuoguan.png', img: imgUrl+'house/zydq.png', bgcolor: 'tg'},
        { type: imgUrl+'house/nodoor.png', img: '', bgcolor: 'wbdm'}
      ],
      housetypeList: [
        { id: 0,text: '空置', color: 'kong', ischeck:false},
        { id: 1,text: '已租', color: 'yizu', ischeck:false},
        { id: 2,text: '欠租', color: 'red', ischeck:false},
        { id: 3,text: '接近交租', color: 'jjjz', ischeck:false},
        { id: 4,text: '租约快结束', color: 'zykjs', ischeck:false},
        { id: 5,text: '未绑定门锁', color: 'wbdms', ischeck:false},
      ],
      outtypeList: [
        { id: 0,text: '合租', color: 'zc', ischeck:false},
        { id: 1,text: '整租', color: 'zc', ischeck:false},
      ],
      houseattributeList: [
        { id: 0,text: '自持', color: 'zc', ischeck:false},
        { id: 1,text: '托管', color: 'zc', ischeck:false},
      ],
      housetype:[],
      outtype:[],
      houseattribute:[],
      isflag: true,
      timer:null,
      search:''
    }
  },
  props: {
    list: {
      type: Array,
      default () {
        return []
      }
    }
  },
  watch: {
    triggered(val,ll){
      console.log('变化了',val,ll)
    }
  },
  computed: {
    baseUrl() {
      return process.env.VUE_APP_BASE_IMG_URL;
    },
    isnone(){
       if(this.list){
         return this.list.length
       }else{
         return false
       }
    },
  },
  created(){
    console.log(111,this.list)
  },
  methods: {
    clickitem(res) {
      res.isitem = this.check(res)
      this.$emit('clickitem',res)
    },
    _onLoadmore(){
      // this.$emit('onRefresh')
    },
    onRefresh(){
      this.$emit('onRefresh')
      console.log('99999,松手了')
      this.triggered = 'restore'
      setTimeout(() => {
        this.triggered = false
      }, 1000)
    },
    clickBtn(item,id){
      switch (id) {
        case 1:
          this.housetypeList[item.id].ischeck = !this.housetypeList[item.id].ischeck
          const index = this.housetype.indexOf(item.id)
          if( index > -1 ){
            this.housetype.splice(index,1)
          }else{
            this.housetype.push(item.id)
          }
          if(this.housetype.length){
            this.$emit('clickBtn','housetype,'+this.housetype)
          }else{
            this.$emit('clickBtn','housetype')
          }
          break;
        case 2:
          this.outtypeList[item.id].ischeck = !this.outtypeList[item.id].ischeck
          const index2 = this.outtype.indexOf(item.id)
          if( index2 > -1 ){
            this.outtype.splice(index2,1)
          }else{
            this.outtype.push(item.id)
          }
          if(this.outtype.length){
            this.$emit('clickBtn','outtype,'+this.outtype)
          }else{
            this.$emit('clickBtn','outtype')
          }
          break;
        case 3:
          this.houseattributeList[item.id].ischeck = !this.houseattributeList[item.id].ischeck
          const index3 = this.houseattribute.indexOf(item.id)
          if( index3 > -1 ){
            this.houseattribute.splice(index3,1)
          }else{
            this.houseattribute.push(item.id)
          }
          if(this.houseattribute.length){
            this.$emit('clickBtn','houseattribute,'+this.houseattribute)
          }else{
            this.$emit('clickBtn','houseattribute')
          }
          break;
      }
    },
    _onPulling(){
      console.log('999刷新刷新。。。。')
    },
    searchInput(e){
      this.search = e.detail.value
      if(!this.isflag) return
      this.isflag = false
      let that = this
      this.timer = setTimeout(function(){
        that.$emit('searchInput',that.search)
        that.isflag = true
      },2000)
    },
    check(item){
      // item.biglocknumber // 大门门锁
      // item.outtype   //合租-0  整租-1
      // item.locknumber  //房间门锁 门锁 0-未绑定，1-已绑定
      // return 0 表示大门没锁 灰色   1表示整租/合租都有门锁 2表示合租大门有锁，小门没锁
      if (item.biglocknumber) {
        if(item.outtype == 1){
          return 1
        }else{
          if(item.locknumber){
            return 1
          }else{
            return 2
          }
        }
      }else{
        return 0
      }
    },
    isImge(item){
      if(item.tag){
        if(item.biglocknumber){
          // 是否租约快到期 0-否，1-是 
          // if(item.isexpire == 1){
          //   return 1
          // }else{
          //   if(item.ispayrent == 1){
          //     // 是否接近交租 0-否，1-是 
          //     return 2
          //   }else{
          //     return false
          //   }
          // }
          let int = 0
          switch (item.tag) {
            // tag = 2 接近交租
            case 2:
              int = 2
              break;
            // tag = 3 租约快到期
            case 3:
              int = 1
              break;
          }
          return int
        }else{
          return false
        }
      }else{
        return false
      }
    }
  },
  beforeDestroy(){
    clearTimeout(this.timer)    
    this.timer = null
  }
}
</script>

<style lang="scss" scoped>
.enddays{
    margin-left: 20rpx;
    font-weight: 800;
    color: #4A4A4A;
    height: 34rpx;
    font-size: 24rpx;
    font-family: PingFangSC-Semibold, PingFang SC;
    line-height: 34rpx;
    span{
      color: #1CDF7C;
    font-weight: 800;
    }
    span.active{
      color: #EF1E13;
    font-weight: 800;
    }
}
.hunk{
  width: 100vw;
  box-sizing: border-box;
  background: #F9F9F9;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  .search{
    height: 50px;
    background: #FFFFFF;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    img{
      width: 14px;
      height: 14px;
      position: absolute;
      top: 18px;
      left: 29px;
    }
    input{
      width: 345px;
      height: 30px;
      background: #F3F2F6;
      border-radius: 20px;
      font-size: 13px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #000;
      line-height: 30px;
      padding-left: 37px;
    }
    input::placeholder{
      color: #9B9B9B;
    }
  }
  .type-list{
    box-sizing: border-box;
    margin-top: 1px;
    background: #FFFFFF;
    width: 100%;
    padding: 10px 6px 0 15px;
    .newItem{
      display: flex;
      justify-content: space-between;
    }
    .type-item{
      width: 100%;
      .item-lable{
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #4a4a4a;
        margin: 0 0 10px 0;
      }
      .item{
        span{
          position: relative;
          display: inline-block;
          // box-sizing: border-box;
          width: 80px;
          height: 26px;
          font-size: 14px;
          font-family: PingFangSC-Semibold, PingFang SC;
          font-weight: 600;
          line-height: 26px;
          text-align: center;
          margin: 0 8px 13px 0;
          img{
            width: 14px;
            height: 14px;
            position: absolute;
            top: 0;
            right: 0;
          }
        }
        span:nth-child(4){
          margin-right: 0;
        }
      }
    }
    .newItem .type-item .item span:nth-child(2){
      margin-right: 0;
    }
    .red{
      background: rgba(254, 65, 55, 0.2);
      border-radius: 4px;
      border: 1px solid #FE4137;
      color: #EF1E13;
    }
    .kong{
      background: rgba(18, 203, 110, 0.2);
      border-radius: 4px;
      border: 1px solid #00CF64;
      color: #00CF64;
    }
    .yizu{
      background: rgba(98, 136, 234, 0.2);
      border-radius: 4px;
      border: 1px solid #6288EA;
      color: #6288EA;
    }
    .jjjz{
      background: rgba(255, 218, 45, 0.2);
      border-radius: 4px;
      border: 1px solid #FFD62D;
      color: #FFE12D;
    }
    .zykjs{
      background: rgba(255, 199, 45, 0.2);
      border-radius: 4px;
      border: 1px solid #FFC72D;
      color: #FFC72D;
    }
    .wbdms{
      background: rgba(130, 130, 130, 0.2);
      border-radius: 4px;
      border: 1px solid #828282;
      color: #828282;
      font-weight: 400;
    }
    .zc{
      background: rgba(252, 145, 58, 0.2);
      border-radius: 4px;
      border: 1px solid #FC913A;
      color: #FC913A;
      font-weight: 400;
    }
  }
  .home-list{
    flex: 1;
    overflow-y: auto;
    .home-item{
      background-color: #fff;
      padding: 20px 15px;
      margin: 10px 0;
    }
    .home-name{
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #000000;
      line-height: 20px;
      word-break:break-all;
      display:-webkit-box;
      -webkit-line-clamp:2;
      -webkit-box-orient:vertical;
      overflow:hidden;
    }
    .item-list{
      margin-top: 10px;
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      .one{
        width: 108px;
        background: rgba(18, 203, 110, 0.2);
        border-radius: 4px;
        padding-bottom: 16px;
        margin: 10px 10px 0 0;
        position: relative;
        .top{
          width: 60px;
          height: 18px;
          // background: #FC913A;
          // border-radius: 4px 0px 12px 0px;
          // font-size: 10px;
          // font-family: PingFangSC-Regular, PingFang SC;
          // font-weight: 400;
          // color: #FFFFFF;
          // line-height: 18px;
          // text-align: center;
          img{
            width: 100%;
            height: 100%;
          }
        }
        .miaoshu{
          width: 89px;
          // height: 45px;
          font-size: 12px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #4A4A4A;
          line-height: 17px;
          margin: 2px 10px;
          word-break:break-all;
          display:-webkit-box;
          -webkit-line-clamp:3;
          -webkit-box-orient:vertical;
          overflow:hidden;
        }
        .yuezu{
          margin-left: 10px;
          color: #4A4A4A;
          height: 17px;
          font-size: 12px;
          font-family: PingFangSC-Semibold, PingFang SC;
          font-weight: 200;
          line-height: 17px;
          span{
            font-weight: 600;
            color: #FF5A65;
          }
        }
        .type1{
          width: 36px;
          height: 24px;
        }
        .type2{
          width: 39px;
          height: 31px;
        }
        .type3{
          width: 44px;
          height: 35px;
        }
        .type{
          position: absolute;
          right: 4px;
          bottom: 4px;
          img{
            width: 100%;
            height: 100%;
          }
        }
      }
      .wbdm{
        background: rgba(130, 130, 130, 0.2);
      }
      .zc{
        background: rgba(18, 203, 110, 0.2);
      }
      .tg{
        background: rgba(98, 136, 234, 0.2);
      }
      .one:nth-child(3n + 3){
        margin-right: 0;
      }
    }
  }
  .none{
    width: 100vw;
    margin-top: 40px;
    // background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    img{
      width: 190px;
      height: 195px;
    }
  }
}
</style>
